package com.isesol.ime.test.base;

import com.google.common.truth.*;
import com.isesol.arch.common.test.*;
import com.isesol.arch.common.utils.*;
import org.junit.*;
import org.junit.rules.*;
import org.junit.runner.*;
import org.junit.runners.model.*;
import org.mockito.*;
import org.slf4j.*;
import org.springframework.test.context.*;
import org.springframework.test.context.junit4.*;

import java.io.*;

/**
 * Spring的支持数据库访问, 事务控制和依赖注入的JUnit4 集成测试基类.
 * 相比Spring原基类名字更短并保存了dataSource变量.
 * <p>
 * 子类需要定义applicationContext文件的位置, 如:
 *
 * @author Henry Yan
 * @ContextConfiguration(locations = { "/applicationContext.xml" })
 */
@ActiveProfiles(Profiles.UNIT_TEST)
public abstract class ResourceTestCase extends AbstractTransactionalJUnit4SpringContextTests {

	private Logger logger = LoggerFactory.getLogger(getClass());

	protected final Expect EXPECT = Expect.create();

	protected final ExpectedException thrown = ExpectedException.none();

	@Rule
	public final TestRule wrapper = new TestRule() {

		@Override
		public Statement apply(Statement base, Description description) {

			Statement expected = EXPECT.apply(base, description);
			return thrown.apply(expected, description);
		}
	};

	@Before
	public void setUp() {

		MockitoAnnotations.initMocks(this);

		try {
			PropertyFileUtil.init();

		} catch ( IOException e ) {

			logger.error("setUp error", e);

		}
	}

}